// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
	env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
	// 获取传参过来的数据
	const {UID, post_time, formData, nickname, avatarUrl, image, userID} = event
	// 将formData的内容进行解构
	const {movie_card_No, location, contact_way} = formData
	// 此云函数是电影卡提交云函数，设置默认数据
	const [tags, type, is_found] = ['lost', '电影卡', false]
	
	return await db.collection('lost_and_found_infos').add({
		data:{
			UID,
			post_time,
			nickname,
			avatarUrl,
			movie_card_No,
			location,
			contact_way,
			tags,
			type,
			is_found,
			image:[image],
			userID
		}
	})
}